Introduction to Poetry
Motivation
- efficient Python project management encompasses multiple crucial steps:
- managing Python versions
- managing virtual environments
- managing dependencies
- package building
- package publishing
- poetry covers almost all these steps
Python Version Management
- not supported with poetry
- instead use pyenv
- in poetry config set
virtualenvs.prefer-active-pythontotrueto make pyenv work with poetry
Environment Management
- virtual environments crucial for dependency management
- poetry creates and activates virtual environments for you
Dependency Management
Why?
- consistency, stability, collaboration, …
Library vs. Application
- Application: versions of dependencies pinned
- Library: more flexibility needed
Dependency Management in poetry
- dependencies are specified in pyproject.toml file
- dependencies can be added by running
poetry add <package_name>- poetry creates a lock file where all versions are pinned
- packages can be installed using the lock file
poetry installPackage Building
- before publishing, a package needs to be build
- building will create a source distribution and a built distribution
poetry buildPackage Publishing
- last step is publishing the package
- poetry will publish to PyPI by default
- credentials need to be configured properly
poetry publish
